package com.bo.sina.weibo.share;

import java.util.HashMap;
import java.util.Map;

public class ShareManager
{
    private static Map<String,ShareInfo> countMap=new HashMap<String,ShareInfo>();
    
    public static void addSuccessShare(String name){
        ShareInfo share=ShareManager.countMap.get(name);
        if(share!=null){
            share.setSuccess(share.getSuccess()+1);
        }else{
            ShareInfo success=new ShareInfo();
            success.setSuccess(1);
            ShareManager.countMap.put(name,success);
        }
    }
    
    public static void addFailShare(String name){
        ShareInfo share=ShareManager.countMap.get(name);
        if(share!=null){
            share.setFail(share.getFail()+1);
        }else{
            ShareInfo fail=new ShareInfo();
            fail.setFail(1);
            ShareManager.countMap.put(name,fail);
        }
    }
    
    public static void toInfo(){
        StringBuffer sb=new StringBuffer("");
        for(Map.Entry<String,ShareInfo> share:ShareManager.countMap.entrySet()){
            sb.append(share.getKey());
            sb.append("= success:");
            sb.append(share.getValue().getSuccess());
            sb.append(" fail:");
            sb.append(share.getValue().getFail());
            sb.append("\n");
        }
        ShareManager.countMap.clear();
    }
}
